<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>io.jenkins.jenkinsfile-runner</groupId>
    <artifactId>parent</artifactId>
    <version>${revision}${changelist}</version>
  </parent>

  <artifactId>packaging-parent-pom</artifactId>
  <packaging>pom</packaging>
  <description>Jenkinsfile Runner: Packaging Parent POM for building custom bundles</description>

  <properties>
    <jfr.name>jenkinsfile-runner-custom-build</jfr.name>
    <!-- FIXME: Support for this parameter is coming in the next JFR release -->
    <jfr.version>1.0-beta-20</jfr.version>
    <!-- Just in case the entry point needs to be overridden -->
    <jfr.mainClass>io.jenkins.jenkinsfile.runner.bootstrap.Bootstrap</jfr.mainClass>

    <!-- Do not package the app using App Assembler (most likely YAGNI, this is for parent POM) -->
    <jfr.skip.packaging>false</jfr.skip.packaging>
    <!-- Do not package the ZIP (Uber Jar is disabled due to https://github.com/jenkinsci/jenkinsfile-runner/issues/350) -->
    <jfr.packaging.skip.assembly>${jfr.skip.packaging}</jfr.packaging.skip.assembly>
    <!-- Do not generate Jenkins WAR and Plugin folders as dependencies -->
    <jfr.packaging.skip.dependencies>${jfr.skip.packaging}</jfr.packaging.skip.dependencies>
    <!--
      TODO(oleg-nenashev): Add support for Uber-JAR. It will require re-greneration or merging of annotation metadata in META-INF.
      Otherwise the files get randomly replaced in the assembly, and the Jenkins core's extension list might be overriden leading to fatal startup issues.
      FTR: https://maven.apache.org/plugins/maven-assembly-plugin/examples/single/using-container-descriptor-handlers.html
     -->
  </properties>

  <build>
    <finalName>${jfr.name}</finalName>

    <plugins>
      <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>retrieve-packaging-resources</id>
            <phase>generate-resources</phase>
            <goals>
              <!-- we use copy as this is a dependency from outside the reactor -->
              <goal>copy</goal>
            </goals>
            <configuration>
              <skip>${jfr.packaging.skip}</skip>
              <artifactItems>
                <artifactItem>
                  <groupId>io.jenkins.jenkinsfile-runner</groupId>
                  <artifactId>packaging-parent-pom-resources</artifactId>
                  <version>${project.parent.version}</version>
                  <classifier>assembly-zip-config</classifier>
                  <type>xml</type>
                  <outputDirectory>${project.build.directory}/generated-sources/assembly</outputDirectory>
                  <destFileName>zip.xml</destFileName>
                </artifactItem>
                <artifactItem>
                  <groupId>io.jenkins.jenkinsfile-runner</groupId>
                  <artifactId>packaging-parent-pom-resources</artifactId>
                  <version>${project.parent.version}</version>
                  <classifier>jenkins-properties</classifier>
                  <type>xml</type>
                  <outputDirectory>${project.build.directory}/generated-sources/resources-filtered</outputDirectory>
                  <destFileName>jenkins.properties</destFileName>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <configuration>
          <skip>${jfr.packaging.skip}</skip>
          <resources>
            <resource>
              <directory>${project.build.directory}/generated-sources/resources-filtered</directory>
              <filtering>true</filtering>
            </resource>
          </resources>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>org.jenkins-ci.main</groupId>
      <artifactId>jenkins-core</artifactId>
      <version>${jenkins.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>io.jenkins.jenkinsfile-runner</groupId>
      <artifactId>bootstrap</artifactId>
      <version>${project.parent.version}</version>
    </dependency>
    <dependency>
      <groupId>io.jenkins.jenkinsfile-runner</groupId>
      <artifactId>setup</artifactId>
      <version>${project.parent.version}</version>
    </dependency>
    <dependency>
      <groupId>io.jenkins.jenkinsfile-runner</groupId>
      <artifactId>payload</artifactId>
      <version>${project.parent.version}</version>
    </dependency>
    <dependency>
      <groupId>io.jenkins.jenkinsfile-runner</groupId>
      <artifactId>payload-dependencies</artifactId>
      <version>${project.parent.version}</version>
    </dependency>
    <dependency>
      <groupId>commons-collections</groupId>
      <artifactId>commons-collections</artifactId>
    </dependency>
    <dependency>
      <groupId>org.jenkins-ci</groupId>
      <artifactId>symbol-annotation</artifactId>
    </dependency>
    <dependency>
      <groupId>org.jenkins-ci</groupId>
      <artifactId>annotation-indexer</artifactId>
    </dependency>
  </dependencies>

  <profiles>
    <profile>
      <id>jfr-package-app</id>
      <activation>
        <file>
          <missing>${project.build.directory}/../parent-pom-marker.txt</missing>
        </file>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>appassembler-maven-plugin</artifactId>
            <version>2.1.0</version>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>assemble</goal>
                </goals>
                <configuration>
                  <programs>
                    <program>
                      <id>jenkinsfile-runner</id>
                      <mainClass>io.jenkins.jenkinsfile.runner.bootstrap.Bootstrap</mainClass>
                    </program>
                  </programs>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>jfr-package-assembly</id>
      <activation>
        <file>
          <missing>${project.build.directory}/../parent-pom-marker.txt</missing>
        </file>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.3.0</version>
            <configuration>
              <skipAssembly>${jfr.packaging.skip.assembly}</skipAssembly>
              <!-- Disabled due to https://github.com/jenkinsci/jenkinsfile-runner/issues/350
              <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
              </descriptorRefs>-->
              <appendAssemblyId>false</appendAssemblyId>
              <archive>
                <manifest>
                  <mainClass>${jfr.mainClass}</mainClass>
                  <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                </manifest>
              </archive>
            </configuration>
            <executions>
              <execution>
                <phase>package</phase>
                <id>package-zip</id>
                <goals>
                  <goal>single</goal>
                </goals>
                <configuration>
                  <descriptors>
                    <descriptor>${project.build.directory}/generated-sources/assembly/zip.xml</descriptor>
                  </descriptors>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>jfr-package-dependencies</id>
      <activation>
        <file>
          <missing>${project.build.directory}/../parent-pom-marker.txt</missing>
        </file>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.jenkins-ci.tools</groupId>
            <artifactId>maven-hpi-plugin</artifactId>
            <executions>
              <execution>
                <id>prepare-plugins-dir</id>
                <phase>compile</phase>
                <goals>
                  <goal>assemble-dependencies</goal>
                </goals>
                <configuration>
                  <!--TODO: Add option to skip this step -->
                  <minimumJavaVersion>8</minimumJavaVersion>
                  <jenkinsCoreVersionOverride>${jenkins.version}</jenkinsCoreVersionOverride>
                  <outputDirectory>${project.build.directory}/plugins</outputDirectory>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>prepare-war</id>
                <phase>compile</phase>
                <goals>
                  <goal>copy</goal>
                </goals>
                <configuration>
                  <skip>${jfr.packaging.skip.dependencies}</skip>
                  <artifactItems>
                    <artifactItem>
                      <groupId>org.jenkins-ci.main</groupId>
                      <artifactId>jenkins-war</artifactId>
                      <version>${jenkins.version}</version>
                      <type>war</type>
                      <outputDirectory>${project.build.directory}/war</outputDirectory>
                      <destFileName>jenkins.war</destFileName>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

  <!--
  <profile>
    <id>jfr-package-uberjar</id>
    <activation>
      <property>
        <name>jfr.package.uberjar</name>
        <value>true</value>
      </property>
    </activation>
    <build>
      <plugins>
      </plugins>
    </build>
  </profile>
</profiles> -->
</project>
